package com.six.result;

public class ResultUtils {

    /**
     * 构建成功带分页
     * @param count
     * @param data
     * @return
     */
    public static Result buildSuccess(Long count,Object data) {
        Result result = new Result();
        result.setMsg(MessageCode.REQUEST_SUCCESS.getMsg());
        result.setCode(MessageCode.REQUEST_SUCCESS.getCode());
        result.setCount(count);
        result.setData(data);
        return result;
    }

    /**
     * 构建单个成功的结果
     * @param data
     * @return
     */
    public static Result buildSuccess(Object data) {
        return buildSuccess(null,data);
    }

    /**
     * 不带数据返回的成功
     * @return
     */
    public static Result buildSuccess() {
        return buildSuccess(null);
    }

    public static Result buildFail(MessageCode messageCode) {
        Result result=new Result();
        result.setCode(messageCode.getCode());
        result.setMsg(messageCode.getMsg());
        return result;
    }

    public static Result buildFail(Integer code,String msg) {
        Result result=new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
